import { GlobalData } from '/store/state'
import { mallApi } from '/api/mall'
import { $event } from "/utils";

Page({
  data: {
    top: GlobalData.menuRect.top,
    height: GlobalData.menuRect.height,
    navigationHeight: GlobalData.navigationHeight,
    info: {} as ExpressesCallback,
    id: 5,
  },
  async onLoad(options: any) {
    wx.hideShareMenu()
    const info = JSON.parse(options.info)
    this.setData({
      info,
      id: +options.id,
    })
  },
  onShow() {
    this.setData({
      top: GlobalData.menuRect.top,
      height: GlobalData.menuRect.height,
      navigationHeight: GlobalData.navigationHeight,
    })
  },
  onMore() {
    const _this = this
    wx.showActionSheet({
      itemList: ['编辑', '删除'],
      success(res) {
        switch (res.tapIndex) {
          case 0:
            wx.navigateTo({
              url: `/mall/fillShipInfo/fillShipInfo?id=${_this.data.info.id}&number=${_this.data.info.number}&company=${_this.data.info.company.name}&companyId=${_this.data.info.company.id}`,
            })
            break

          case 1:
            _this.delete()
        }
      },
    })
  },
  delete() {
    const _this = this
    wx.showActionSheet({
      itemList: ['确定删除物流信息吗?'],
      itemColor: '#FF0000',
      async success(res) {
        switch (res.tapIndex) {
          case 0:
            await mallApi.deletExpresses(+_this.data.info.id)
            wx.showToast({
              title: '成功删除此快递信息',
            })
            $event.emit('mallOrderChange')
            setTimeout(() => {
              wx.navigateBack({
                delta: 1,
              })
            }, 1000)
            break
        }
      },
    })
  },
})
